package com.demo.web.pc;

import com.demo.dto.BaseResult;
import com.demo.dto.ListResult;
import com.demo.entity.Goods;
import com.demo.entity.GoodsPriceIndex;
import com.demo.service.IGoodsPriceIndexService;
import com.demo.service.IGoodsService;
import com.demo.service.IOfferService;
import com.demo.vo.GoodsPriceIndexVo;
import com.demo.vo.GoodsVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/goods")
public class GoodsPcController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IGoodsService depService;
    @Autowired
    private IOfferService offerService;
    @Autowired
    private IGoodsPriceIndexService gpiService;

    @ResponseBody
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public BaseResult<Map> index(GoodsPriceIndexVo arg, HttpSession session) {
        List<GoodsPriceIndex> list = gpiService.queryByPageAndGoodsId(arg);
        Goods goods = depService.selectByPrimaryKey(Integer.valueOf(arg.getGoodsId()));
        Map map = new HashMap();
        map.put("goods", goods);
        map.put("prices", list);
        BaseResult<Map> res = new BaseResult(true, map);
        return res;
    }
    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult query(GoodsVo arg) {
        arg.setOnline("1");
        List<Goods> list = depService.queryGoodsCategory(arg);
        ListResult res = new ListResult(true, list);
        return res;
    }
}
